package com.washmadam.service.controller.cms.manager;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.washmadam.service.common.base.BaseController;
import com.washmadam.service.common.base.RequestDTO;
import com.washmadam.service.common.base.ResponseDTO;
import com.washmadam.service.common.constants.Constant;
import com.washmadam.service.db.dto.Manager;
import com.washmadam.service.service.manager.ManagerService;

import common.service.base.annotation.NoCheckSession;
import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping(Constant.URL_PREFIX + "/cms/login")
@Slf4j
public class LoginCmsController extends BaseController {

    @Autowired
    ManagerService managerService;
    
    @RequestMapping(value = "/login_in")
    @NoCheckSession
    public String doLoginIn(@RequestBody RequestDTO req, HttpServletRequest request) {
        try {
        	String loginInfo = JSON.toJSONString(req.getData());
        	log.info("【后台登陆】登录接口请求参数:{}", loginInfo);
        	Manager result = managerService.queryManagerDetail(JSONObject.parseObject(loginInfo, Manager.class));
            return ResponseDTO.success(result);
        } catch (Exception e) {
        	log.error("【后台登陆】异常，{}", e);
            return ResponseDTO.fail("请求异常:"+e.getMessage(), null);
        }
    }
}

